/*
 * @Author: JohnYang
 * @Date: 2020-08-16 21:56:26
 * @LastEditors: JohnYang
 * @LastEditTime: 2020-09-30 23:50:11
 */

import {
  BrandMap,
  ProductEnumsMap,
  VehiclePropertyEnumsMap,
  CertificateEnumsMap,
  ManufacturerProtectTimeEnumsMap,
  ExtendTimeSolutionEnumsMap,
  CalcMethodEnumsMap,
  QualitySolutionEnumsMap,
  GearBoxEnumsMap,
  VehicleModelMap,
  RegionMap
} from "./storage";

export function renderDatetime(pattern) {
  return function(val) {
    if (!val) {
      return "--";
    }
    return new Date(val).format(pattern);
  };
}

export function renderProduct(val) {
  var node = ProductEnumsMap[val] || {};
  return node.label || "--";
}

export function renderVehicleProperty(val) {
  var node = VehiclePropertyEnumsMap[val] || {};
  return node.label || "--";
}

export function renderCertificateType(val) {
  var node = CertificateEnumsMap[val] || {};
  return node.label || "--";
}

export function renderProtectTime(val) {
  var node = ManufacturerProtectTimeEnumsMap[val] || {};
  return node.label || "--";
}

export function renderExtendTimeSolution(val) {
  var node = ExtendTimeSolutionEnumsMap[val] || {};
  return node.label || "--";
}

export function renderCalcMethod(val) {
  var node = CalcMethodEnumsMap[val] || {};
  return node.label || "--";
}

export function renderQualitySolution(val) {
  var node = QualitySolutionEnumsMap[val] || {};
  return node.label || "--";
}

export function renderBrand(val) {
  var node = BrandMap[val] || {};
  return node.label || "--";
}

export function renderGearBox(val) {
  var node = GearBoxEnumsMap[val] || {};
  return node.label || "--";
}

export function renderRegion(val) {
  var node = RegionMap[val] || {};
  return node.label || "--";
}

export function renderVehicleModel(val) {
  var node = VehicleModelMap[val] || {};
  return node.name || "--";
}

export function renderAuditState(state) {
  return state == 2 ? "拒绝" : state == 1 ? "通过" : "待审批";
}

export var RenderMixin = {
  methods: {
    renderDate(val) {
      return renderDatetime("yyyy-MM-dd")(val);
    },
    renderDateTime(val) {
      return renderDatetime("yyyy-MM-dd hh:mm:ss")(val);
    },
    renderTime(val) {
      return renderDatetime("MM-dd hh:mm:ss")(val);
    },
    renderGearBox,
    renderBrand,
    renderProduct,
    renderVehicleProperty,
    renderCertificateType,
    renderProtectTime,
    renderExtendTimeSolution,
    renderCalcMethod,
    renderQualitySolution,
    renderRegion,
    renderVehicleModel,
    renderAuditState
  },
  filters: {
    renderDate(val) {
      return renderDatetime("yyyy-MM-dd")(val);
    },
    renderTime(val) {
      return renderDatetime("MM-dd hh:mm:ss")(val);
    },
    renderDateTime(val) {
      return renderDatetime("yyyy-MM-dd hh:mm:ss")(val);
    },
    renderGearBox,
    renderBrand,
    renderProduct,
    renderVehicleProperty,
    renderCertificateType,
    renderProtectTime,
    renderExtendTimeSolution,
    renderCalcMethod,
    renderQualitySolution,
    renderRegion,
    renderVehicleModel,
    renderAuditState
  }
};
